package huachenxing.mimi520.option.models
{
	import huachenxing.mimi520.tools.ConfigFile;

	public class WorkerModel
	{
		private static var _retry:int = 3;
		private static var _query:int = 3;
		private static var _answer:int = 5;
		
		public static function get answer():int
		{
			return _answer;
		}
		public static function set answer(value:int):void
		{
			if(value < 3) value = 3;
			_answer = value;
		}

		public static function get query():int
		{
			return _query;
		}
		public static function set query(value:int):void
		{
			if(value < 3) value = 3;
			_query = value;
		}

		public static function get retry():int
		{
			return _retry;
		}
		public static function set retry(value:int):void
		{
			if(value < 2) value = 2;
			_retry = value;
		}

		public static function fromConfig():void
		{
			var config:ConfigFile = new ConfigFile("worker");
			config.read();
			
			for(var key:String in config)
			{
				var value:String = config[key];
				try { WorkerModel[key] = int(value); }
				catch(e) {}
			}
		}
		
		public static function toConfig():void
		{
			var config:ConfigFile = new ConfigFile("worker");
			config["retry"] = WorkerModel.retry;
			config["query"] = WorkerModel.query;
			config["answer"] = WorkerModel.answer;
			config.write();
		}
	}
}